<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
  <head>
    <th:block th:include="include :: header('新增红色书籍')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: bootstrap-fileinput-css" />
  </head>
  <body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
      <form class="form-horizontal m" id="form-redBook-add">
        <div class="col-xs-12">
          <div class="form-group">
            <label class="col-sm-3 control-label is-required">书籍标题：</label>
            <div class="col-sm-8">
              <input name="title" class="form-control" type="text" required />
            </div>
          </div>
        </div>
        <div class="col-xs-12">
          <div class="form-group">
            <label class="col-sm-3 control-label">是否启用：</label>
            <div class="col-sm-8">
              <input name="status" type="radio" value="0" />
              <label>不启用</label>
              <input name="status" type="radio" value="1" checked />
              <label>启用</label>
            </div>
          </div>
        </div>
        <div class="col-xs-12">
          <div class="form-group">
            <label class="col-sm-3 control-label">作者：</label>
            <div class="col-sm-8">
              <input name="author" class="form-control" type="text" />
            </div>
          </div>
        </div>
        <div class="col-xs-12">
          <div class="form-group">
            <label class="col-sm-3 control-label">出版社：</label>
            <div class="col-sm-8">
              <input name="publisher" class="form-control" type="text" />
            </div>
          </div>
        </div>
        <div class="col-xs-12">
          <div class="form-group">
            <label class="col-sm-3 control-label">出版日期：</label>
            <div class="col-sm-8">
              <div class="input-group date">
                <input
                  name="publishDate"
                  class="form-control"
                  placeholder="yyyy-MM-dd"
                  type="text"
                />
                <span class="input-group-addon"
                  ><i class="fa fa-calendar"></i
                ></span>
              </div>
            </div>
          </div>
        </div>
        <div class="col-xs-12">
          <div class="form-group">
            <label class="col-sm-3 control-label">封面图片：</label>
            <div class="col-sm-8">
              <input type="hidden" name="coverUrl" />
              <div class="file-loading">
                <input
                  class="form-control file-upload"
                  id="coverUrl"
                  name="file"
                  type="file"
                />
              </div>
            </div>
          </div>
        </div>
        <div class="col-xs-12">
          <div class="form-group">
            <label class="col-sm-3 control-label is-required">电子书：</label>
            <div class="col-sm-8">
              <input type="hidden" name="bookUrl" />
              <div class="file-loading">
                <input
                  class="form-control file-upload"
                  id="bookUrl"
                  name="file"
                  type="file"
                />
              </div>
            </div>
          </div>
        </div>
        <div class="col-xs-12">
          <div class="form-group">
            <label class="col-sm-3 control-label">书籍描述：</label>
            <div class="col-sm-8">
              <textarea name="description" class="form-control"></textarea>
            </div>
          </div>
        </div>

        <!--            <div class="col-xs-12">-->
        <!--                <div class="form-group">-->
        <!--                    <label class="col-sm-3 control-label">二维码图片：</label>-->
        <!--                    <div class="col-sm-8">-->
        <!--                        <input type="hidden" name="qrCodeUrl">-->
        <!--                        <div class="file-loading">-->
        <!--                            <input class="form-control file-upload" id="qrCodeUrl" name="file" type="file">-->
        <!--                        </div>-->
        <!--                    </div>-->
        <!--                </div>-->
        <!--            </div>-->
      </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: bootstrap-fileinput-js" />
    <script th:inline="javascript">
      var prefix = ctx + "learn/redBook";
      $("#form-redBook-add").validate({
        focusCleanup: true,
      });

      function submitHandler() {
        if ($.validate.form()) {
          $.operate.save(prefix + "/add", $("#form-redBook-add").serialize());
        }
      }

      $("input[name='publishDate']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true,
      });

      $(".file-upload")
        .fileinput({
          uploadUrl: ctx + "common/upload",
          maxFileCount: 1,
          autoReplace: true,
          showUpload: false,
          uploadAsync: true,
        })
        .on("filebatchselected", function () {
          $(this).fileinput("upload");
        })
        .on("fileuploaded", function (event, data, previewId, index) {
          $("input[name='" + event.currentTarget.id + "']").val(
            data.response.fileName
          );
        })
        .on("fileremoved", function (event, id, index) {
          $("input[name='" + event.currentTarget.id + "']").val("");
        });
    </script>
  </body>
</html>
